package extration;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map.Entry;

public class Run {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Data d = new Data();
		d.readfile();
		
		System.out.println("Calcul");
		d.calculKhi();
		//Writefichier(d);
		System.out.println("fini");
		//System.out.println("Ecriture");
		//Writefichier(d);
		//System.out.println("fin");
		//for(Mot m : d.calculTopFrequent()){
			//System.out.println(m.getChaine() + " occ " + m.getNbOccGenerale());
		//}
		/*ArrayList<Mot> topFrequent = d.calculTopFrequent();
		d.calculTopSignificative();
		d.calculTFlopSignificative();*/
		/*
		System.out.println("nbMot total "  + d.getNbMotTotal());
		System.out.println("nb Mot different " + d.getNbMot());
		System.out.println("longueur moyenne " + d.calculLongueur());*/
	
		
		ModeleMultinomial mb = new ModeleMultinomial(d);
		int taille = d.getLesMessages().size();
		int largeur = taille/10;
		int indexDebut = 0;
		int indexFin = largeur;
		int cpt =1;
		float f=0.0f;
		System.out.println("Lancement du test BINOMIAL");
		while (taille-indexFin>largeur){
			System.out.println("Test " + cpt + " en cours...");
			mb.createTestFile(indexDebut, indexFin);
			mb.parametreMultimonial();
			f+=mb.lancerClassification(cpt);
			cpt++;
			indexDebut = indexFin;
			indexFin +=largeur;
			
		//mb.affiche();
		}
		System.out.println("moyenne " + f/(float)cpt);
		
		/*ModeleMultinomial m = new ModeleMultinomial(d);
		taille = d.getLesMessages().size();
		largeur = taille/10;
		indexDebut = 0;
		indexFin = largeur;
		cpt =1;
		System.out.println("Lancement du test MULTINOMIAL");
		while (taille-indexFin>largeur){
			System.out.println("Test " + cpt + " en cours...");
			m.createTestFile(indexDebut, indexFin);
			m.parametreMultimonial();
			m.lancerClassification(cpt);
			cpt++;
			indexDebut = indexFin;
			indexFin +=largeur;
			
		//mb.affiche();
		}*/
		/*d.removeMot(d.getPolarite().get(Data.NEGATIVE).getTopSignificatif());
		d.removeMot(d.getPolarite().get(Data.IRRELEVANT).getTopSignificatif());
		d.removeMot(d.getPolarite().get(Data.POSITIVE).getTopSignificatif());
		d.removeMot(d.getPolarite().get(Data.NEUTRAL).getTopSignificatif());*/
		
		/*d.removeMot(d.getPolarite().get(Data.NEGATIVE).getFlopSignificatif());
		d.removeMot(d.getPolarite().get(Data.IRRELEVANT).getFlopSignificatif());
		d.removeMot(d.getPolarite().get(Data.POSITIVE).getFlopSignificatif());
		d.removeMot(d.getPolarite().get(Data.NEUTRAL).getFlopSignificatif());*/
		
		//d.removeMot(topFrequent);
		
		/*float f=0.0f;
		d.readfileTest();
		ModeleBinomial modele = new ModeleBinomial(d);
		taille = d.getLesMessagesTest().size();
		ArrayList<String> resultat = new ArrayList<String>();
		System.out.println("Test " + cpt + " en cours...");
		modele.createTest(d.getLesMessagesTest(),d.getLesMessages());
		modele.parametreBinomial();
		//modele.affiche();
		//modele.validationCroisePredilection();
		f=modele.lancerClassificationACout(0);
		//resultat.addAll(modele.getPredilectionMessage());
		System.out.println("Moyenne : " + f);
		//WritefichierPredilection(resultat);
		System.out.println("FIN ");*/
		
		
	}
	
	public static void Writefichier(Data d){
		try {
			FileWriter fw = new FileWriter("resultat.txt");
			for(Entry<String,Polarite> hm : d.getPolarite().entrySet()){
				System.out.println("------ " + hm.getKey() + "--------");
				Polarite p = hm.getValue();
				fw.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" + hm.getKey() + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
				for(Message msg : p.getMessages()){
					fw.write(msg.toString());
				}
				fw.write("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
			}
			
			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public static void WritefichierPredilection(ArrayList<String> chaine){
		try {
			FileWriter fw = new FileWriter("LOPEZ-PHILIPPS-test-eit-12.txt");
			for(String str : chaine)
				fw.append(str + "\n");
			
			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
